﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using YJKRevitDictionary.Operation;

namespace YJKRevitDimensionText.Forms
{
	public partial class DlgEditEntry : System.Windows.Forms.Form
	{
		public DlgEditEntry(DlgDictForm mForm)
		{
			this.mainForm = mForm;
			this.InitializeComponent();
			if (this.mainForm.lbxEntry.SelectedItem != null)
			{
				this.tbxName.Text = ((StringEntry)this.mainForm.lbxEntry.SelectedItem).Name;
				this.rtbIndex.Text = ((StringEntry)this.mainForm.lbxEntry.SelectedItem).Text;
			}
		}

		private void btnAdd_Click(object sender, EventArgs e)
		{
			if (this.mainForm.lbxEntry.SelectedItem != null)
			{
				if (DictOperation.EditStringEntry(((StringEntry)this.mainForm.lbxEntry.SelectedItem).XNode, this.tbxName.Text, this.rtbIndex.Text, this.mainForm.dictFile.FullName, true))
				{
					TreeNode selectedNode = this.mainForm.treeView1.SelectedNode;
					this.mainForm.lbxEntry.Items.Clear();
					XmlNode node = (XmlNode)selectedNode.Tag;
					this.mainForm.GetChildAttributes(node, this.mainForm.lbxEntry);
					this.mainForm.lbxEntry.Sorted = true;
					MessageBox.Show("修改成功", "盈建科词库");
				}
				else
				{
					MessageBox.Show("修改失败", "盈建科词库");
				}
			}
			base.Close();
		}

		public static DlgEditEntry GetInstance(DlgDictForm main)
		{
			if (DlgEditEntry.dee == null || DlgEditEntry.dee.IsDisposed)
			{
				DlgEditEntry.dee = new DlgEditEntry(main);
				DlgEditEntry.dee.MdiParent = main.ActiveMdiChild;
			}
			return DlgEditEntry.dee;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private DlgDictForm mainForm;

		private static DlgEditEntry dee;
	}
}
